# -*- coding: utf-8 -*-
# @Time    : 2021/4/9 19:38
# @Author  : Zhangrenjie
# @Email   : zhangrenjie1998@163.com
# @File    : name_input.py
# @Software: PyCharm


with open('guest.txt', 'a', encoding='utf-8') as f:
    while True:
        name = input("请输入名字：\n 输入 q 退出")
        if name == 'q':
            break
        else:
            f.write(f'{name}\n')
            f.flush()